﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace InteSoft.Web.ExternalResourceLoader
{
    public class SchemeElement : ConfigurationElement
    {
        private static ConfigurationProperty _propDomains;
        private static ConfigurationProperty _propName;
        private static ConfigurationProperty _propResourceRoot;
        private static ConfigurationPropertyCollection _properties;

        public SchemeElement()
        {
            EnsureStaticPropertyBag();
        }

        private static ConfigurationPropertyCollection EnsureStaticPropertyBag()
        {
            if (_properties == null)
            {
                _propDomains = new ConfigurationProperty("", typeof(ContentCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
                _propName = new ConfigurationProperty("name", typeof(string), string.Empty, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
                _propResourceRoot = new ConfigurationProperty("resourceRoot", typeof(string), string.Empty, ConfigurationPropertyOptions.None);

                _properties = new ConfigurationPropertyCollection
                                  {
                                      _propDomains,
                                      _propName,
                                      _propResourceRoot
                                  };
            }
            return _properties;
        }

        [ConfigurationProperty("name", DefaultValue = "")]
        public string Name
        {
            get { return (string)base[_propName]; }
            set { base[_propName] = value; }
        }

        [ConfigurationProperty("resourceRoot", DefaultValue = "")]
        public string ResourceRoot
        {
            get { return (string)base[_propResourceRoot]; }
            set { base[_propResourceRoot] = value; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return EnsureStaticPropertyBag(); }
        }

        [ConfigurationProperty("", IsDefaultCollection = true)]
        public ContentCollection Contents
        {
            get { return (ContentCollection)base[_propDomains]; }
        }
    }
}
